﻿using Unity.VisualScripting;
using UnityEngine;

public class PlayerWallRun : PlayerBaseState {
	Timer _timer = new();
	bool _runOver;
	Vector2 _wallRunSpeed;
	public PlayerWallRun(PlayerController controller, PlayerStateEnum stateName, State<PlayerStateEnum> superFSM, StateFactory<PlayerStateEnum> factory) : base(controller, stateName, superFSM, factory) {
		AddConditionToSelf(() => _controller.IsTouchingWall && _controller.Velocity.y > 0);

		AddNewTransition(PlayerStateEnum.WallIdle, () => _runOver);
		_wallRunSpeed = new Vector2(0, _controller.ConfigData.WallRunSpeed);
	}

	public override void Enter() {
		_timer.Reset();
		_controller.PlayAnim(PlayerStateEnum.WallRun);
		_runOver = false;
		_controller.Velocity = _wallRunSpeed;
	}

	public override void Update() {
		base.Update();
		if (_timer.Elapsed > _controller.ConfigData.WallRunTime) {
			_runOver = true;
		}
	}

	public override void Exit() {
		_controller.Velocity = Vector2.zero;
	}
}